package com.gxgeek.javabasic.reflect;

import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Arrays;

@Slf4j
public class RefletAnnotation {

    @AnnotationTest01
    public static void main(String[] args) {
        try {
            new RefletAnnotation().test();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
    }
    @Transactional
    public void test() throws NoSuchMethodException, SecurityException{
        StackTraceElement[] stack = new Throwable().getStackTrace();
        log.info(stack[1].getMethodName());
        Arrays.stream(stack).forEach(s->log.info(s.getMethodName()));
        Method method = this.getClass().getMethod(stack[1].getMethodName(),String[].class);
        for(Annotation an : method.getAnnotations()){
            System.out.println(an);
        }
    }

}
